﻿namespace com.oakwoodsys.ConsultantCareDao
{
    using System.Linq;

    using com.oakwoodsys.SharePoint;

    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Linq;

    using Context = ConsultantCareDataContext;

    using ReferenceObject = ConsultantCareConfiguration;

    public class ConsultantCareConfigurationDao : BaseDao
    {
        #region Fields

        public const string ListName = "configuration";

        #endregion Fields

        #region Constructors

        public ConsultantCareConfigurationDao( )
            : base(ListName)
        {
            CurrentWebUrl = SPContext.Current.Web.Url;
        }

        public ConsultantCareConfigurationDao( string currentWebUrl )
            : base(ListName)
        {
            CurrentWebUrl = currentWebUrl;
        }

        #endregion Constructors

        #region Methods

        public ReferenceObject Get( )
        {
            using ( Context c = new Context( CurrentWebUrl ) )
            {
                EntityList<ReferenceObject> l = c.GetList<ReferenceObject>( ListTitle );
                ReferenceObject v = ( from o in l
                                            where o.Active.HasValue && o.Active.Value
                                            select o ).FirstOrDefault( );
                return v;
            }
        }

        #endregion Methods
    }
}